package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import java.util.*;
import java.io.*;
import bean.*;

public final class booklist_005fok_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.List _jspx_dependants;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=EUC-KR");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      bean.BookMember books = null;
      synchronized (_jspx_page_context) {
        books = (bean.BookMember) _jspx_page_context.getAttribute("books", PageContext.PAGE_SCOPE);
        if (books == null){
          books = new bean.BookMember();
          _jspx_page_context.setAttribute("books", books, PageContext.PAGE_SCOPE);
        }
      }
      out.write('\r');
      out.write('\n');

	request.setCharacterEncoding("euc-kr");
	String realFolder = "";
	int maxSize = 1024*1024*5;
	String encType = "euc-kr";
	String savefile = "file";
	ServletContext scontext = getServletContext();
	realFolder = scontext.getRealPath(savefile);
	MultipartRequest multi = null;
	multi = new MultipartRequest(request,realFolder,maxSize,encType,new DefaultFileRenamePolicy());
	try{
	
		
		String bookstri = multi.getParameter("bookstri");
		String title = multi.getParameter("title");
		String price = multi.getParameter("price");
		String quantity = multi.getParameter("quantity");
		String writer = multi.getParameter("writer");
		String pub = multi.getParameter("pub");
		String year = multi.getParameter("year");
		String m = multi.getParameter("m");
		String d = multi.getParameter("d");
		String pub_day = (year+"/"+m+"/"+d);
		Enumeration files = multi.getFileNames();
		String name1 = (String)files.nextElement();
		String name = multi.getFilesystemName(name1);
		Enumeration params = multi.getParameterNames();
		
		String discount = multi.getParameter("discount");
		String text = multi.getParameter("text");
		
		//boolean flag = books.insertBoard(title);
		boolean flag = books.insertBoard(bookstri,title,price,quantity,writer,pub,pub_day,discount,text,name);
		
		if(flag){
		System.out.println("저장 되었습니다");
		}else{
		System.out.println("저장 되지 않았습니다");
		}
		

		while(params.hasMoreElements()){
			String name2 = (String)params.nextElement();
			String value1 = multi.getParameter(name2);
			multi.getParameter(name2);
			//out.println(name1+":");
			//out.println(value+"<br>");
		}
		
	while(files.hasMoreElements()){
		String name2 = (String)files.nextElement();
		String filename1 = multi.getFilesystemName(name2);
		String original1 = multi.getOriginalFileName(name2);
		String contentType = multi.getContentType(name2);
		File f = multi.getFile(name2);
		out.println("name:"+name1+"<br>");
		out.println("file:"+filename1+"<br>");
		out.println("orig:"+original1+"<br>");
		out.println("content:"+contentType+"<br>");
		out.println("ff"+f+"<br>");
	}
		
	}catch(Exception e){
		System.out.println("북 에러"+e);
	}
Vector v = books.book_chk();
int Result = v.size();

      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-KR\">\r\n");
      out.write("<title>Insert title here</title>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("<center>\r\n");
      out.write("<table border=\"1\" width=\"500\">\r\n");
      out.write("\t<tr>\r\n");
      out.write("\t\t<td>번호</td><td>책종목</td><td>이미지</td>\r\n");
      out.write("\t</tr>\r\n");

for(int q=0; q<Result; q++){
BookBean book = (BookBean)v.get(q);

      out.write("\r\n");
      out.write("\t<tr>\r\n");
      out.write("\t\t<td>");
      out.print(book.getNos() );
      out.write("</td>\r\n");
      out.write("\t\t<td>");
      out.print(book.getBookstri() );
      out.write("</td>\r\n");
      out.write("\t\t<td><img src=\"file/");
      out.print(book.getBookimg() );
      out.write("\" width=\"50\" height=\"50\"></td>\r\n");
      out.write("\t</tr>\r\n");
      out.write("\r\n");
}
      out.write("\r\n");
      out.write("\r\n");
      out.write("</table>\r\n");
      out.write("</center>\r\n");
      out.write("</body>\r\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
